<template>
	<basic-container>
		<avue-crud :option="option" :data="data" ref="crud" v-model="form" :permission="permissionList" :page="page"
		 @refresh-change="refreshChange" @search-change="searchChange" @search-reset="searchReset" @current-change="currentChange"
		 @size-change="sizeChange" @on-load="onLoad">
			<template slot-scope="scope" slot="menu">
				<el-button style="padding-right: 20px" type="text" size="small" v-if="scope.row.deductionOfCharges==0" @click="editBtn(scope.row)">编辑</el-button>
				<el-button type="text" size="small" @click="delNew(scope.row)">删除</el-button>
				<el-button type="text" size="small" @click="detail(scope.row)">查看</el-button>
				<el-button type="text" size="small" @click="biddingDetail(scope.row.id)">扣费明细</el-button>
			</template>
			<!-- 是否开启 -->
			<template slot-scope="{row}" slot="adStatus">
				<el-switch :disabled="row.deductionOfCharges!=0" @change="rowSwitchChange(row)" v-model="row.adStatus" active-value="1"
				 inactive-value="0" active-color="#13ce66" inactive-color="#ff4949">
				</el-switch>
			</template>
		</avue-crud>
		<!-- 新增 -->
		<el-dialog :title="title" :visible.sync="dialogVisible" width="60%" @closed="closeDialog('addForm')">
			<el-form :model="addForm" :rules="addrules" ref="addForm" label-width="100px">
				<el-form-item label="广告名称" prop="adTitle">
					<el-input :disabled="isView" v-model="addForm.adTitle"></el-input>
				</el-form-item>
				<el-form-item label="广告位" prop="adApId">
					<el-select :disabled="isView||isApView" v-model="addForm.adApId" placeholder="请选择所属广告位" @change="getPosData">
						<el-option v-for="item in posData" :key="item.value" :label="item.label" :value="item.value">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="标记" prop="mark">
					<el-radio-group v-model="mark">
						<el-radio disabled label='1'>电脑</el-radio>
						<el-radio disabled label='2'>手机</el-radio>
					</el-radio-group>
				</el-form-item>
				<el-form-item label="竞价" v-if="this.addForm.adApId!=''">
					<div>
						<el-col :span="12">
							<el-form-item prop="adPrice">
								<el-tooltip class="item" effect="dark" content="竞价相同时，先出价的排在前面" placement="top-start">
									<el-input :disabled="isView" v-model="addForm.adPrice" @change="changeAdPrice"></el-input>
								</el-tooltip>
							</el-form-item>
						</el-col>
						<el-col :span="10">
							<el-form-item>
								<el-button :disabled="isView" icon="el-icon-search" type="primary" @click="look">查询</el-button>
							</el-form-item>
						</el-col>
					</div>

				</el-form-item>
				<div class="adType">
					<el-form-item label="广告类型" prop="adType">
						<el-select :disabled='isView' v-model="addForm.adTypeName" placeholder="请选择广告类型" @change="getAdType">
							<el-option v-for="item in typeData" :key="item.label" :lable="item.lable" :value="item.value">
								<span style="float: left">{{ item.label }}</span>
							</el-option>
						</el-select>
					</el-form-item>
					<!-- <el-form-item :label="idTitle"
                        prop="adTypeValue">
            <el-col :span="12">
              <el-input v-model="addForm.adTypeValue"></el-input>
            </el-col>
          </el-form-item>-->
					<el-form-item v-show="addForm.adType == 1" label="选择商品" prop="selectGoods">
						<el-select :disabled='isView' placeholder="请输入关键词" filterable @visible-change="getSelectList" remote :remote-method="getSelectList" v-model="value"
						 popper-class="selectJob" size="mini">
							<el-option v-for="item in restoreTable" :key="item.id" :label="item.goodsName" :value="item.id">
								<span style="float: left;width:120px" :title="item.goodsName">{{ item.goodsName }}</span>
							</el-option>
							<div style="text-align:center">
								<span class="text" v-show="selectPage!=1" @click.stop="prevePage">上一页</span>
								<span class="text" style="padding-left: 30px;" @click.stop="nextPage" v-show="selectPage !=pageCount">
									下一页
								</span>
							</div>
						</el-select>
					</el-form-item>
					<el-form-item v-show="addForm.adType == 2" label="选择店铺" prop="selectStore">
						<el-select :disabled='isView' placeholder="请输入关键词" filterable @visible-change="getSelectList" remote :remote-method="getSelectList" v-model="value"
						 popper-class="selectJob" size="mini">
							<el-option v-for="item in restoreTable" :key="item.id" :label="item.storeName" :value="item.id">
								<span style="float: left;width:120px" :title="item.storeName">{{ item.storeName }}</span>
							</el-option>
							<!--<div style="text-align:center">-->
							<!--<span class="text" v-show="" @click.stop="prevePage">上一页</span>-->
							<!--<span class="text" style="padding-left: 30px;" @click.stop="nextPage">-->
							<!--下一页-->
							<!--</span>-->
							<!--</div>-->
						</el-select>
					</el-form-item>
					<el-form-item v-show="addForm.adType == 4 || addForm.adType == 6 || addForm.adType == 8" label="选择活动" prop="selectAct">
						<el-select :disabled='isView' placeholder="请输入关键词" filterable @visible-change="getSelectList" remote :remote-method="getSelectList" v-model="value"
						 popper-class="selectJob" size="mini">
							<el-option v-for="item in restoreTable" :key="item.id" :label="item.acTitle" :value="item.id">
								<span style="float: left;width:120px" :title="item.acTitle">{{ item.acTitle }}</span>
							</el-option>
							<div style="text-align:center">
								<span class="text" v-show="selectPage!=1" @click.stop="prevePage">上一页</span>
								<span class="text" style="padding-left: 30px;" @click.stop="nextPage" v-show="selectPage !=pageCount">
									下一页
								</span>
							</div>
						</el-select>
					</el-form-item>
				</div>
				<el-form-item label="开始时间" prop="adBeginTime">
					<el-date-picker :readonly="isView" @change="checkStartTime" v-model="addForm.adBeginTime" value-format="yyyy-MM-dd HH:mm:ss"
					 format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择日期">
					</el-date-picker>
				</el-form-item>
				<el-form-item label="结束时间" prop="adEndTime">
					<el-date-picker :readonly="isView" @change="getAddTime" v-model="addForm.adEndTime" value-format="yyyy-MM-dd HH:mm:ss"
					 format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择日期">
					</el-date-picker>
				</el-form-item>
				<div class="adAccUrl">
					<el-form-item label="广告图片">
						<div>
							<el-col :span="12">
								<el-form-item prop="adAccUrl">
									<el-input :disabled="isView" v-model="addForm.adAccUrl" placeholder="图片比例：1：1"></el-input>
								</el-form-item>
							</el-col>
							<el-col style="width: 40px;height: 40px;overflow: hidden;margin-left: 15px;background: #f5f6f7;text-align: center;">
								<div class="demo-image__preview">
									<el-image :src="addForm.adAccUrl" width="40" height="40" :preview-src-list="addForm.adAccUrl.split(',')">
										<div slot="error" class="image-slot">
											<i class="el-icon-picture-outline"></i>
										</div>
									</el-image>
								</div>
							</el-col>
							<el-col style="width: 90px;margin-left: 15px;">
								<el-form-item>
									<el-button :disabled="isView" icon="el-icon-search" type="primary" @click="$refs.selFile.open()">预览</el-button>
									<selFile ref="selFile" @callback="selFileCallBack" albumCode="store" dialogTitle="选择图片" selectType="radio"
									 selMaxWidth="300px" selMaxHeight="300px"></selFile>
								</el-form-item>
							</el-col>
						</div>
					</el-form-item>
				</div>
			</el-form>
			<span slot="footer" class="dialog-footer">
				<el-button type="primary" v-if="!isView" @click="submitAdvert('addForm')" :loading="load">确 定</el-button>
				<el-button v-if="!isView" @click="closeDialog('addForm')">取 消</el-button>
				<el-button v-if="isView" @click="closeDialog('addForm')">关闭</el-button>
			</span>
			<el-dialog width="40%" title="竞价列表" :visible.sync="innerVisible" append-to-body>
				<!--				表格-->
				<el-table :data="tableData" style="width: 100%">
					<el-table-column prop="adTitle" label="广告名">
					</el-table-column>
					<el-table-column prop="adPrice" label="价格/元">
					</el-table-column>
					<el-table-column prop="probability" label="概率">
					</el-table-column>
				</el-table>
			</el-dialog>
		</el-dialog>
		<el-drawer size="60%" title="扣费明细" :visible.sync="moneyDetail" append-to-body>
			<div style="padding: 20px;">
				<avue-crud :option="optionMoney" :data="dataMoney" ref="crudMoney" v-model="formMoney" :permission="permissionList"
				 :page="pageMoney" @refresh-change="refreshMoneyChange" @current-change="currentMoneyChange" @size-change="sizeMoneyChange"
				 @on-load="onMoneyLoad">
				</avue-crud>
			</div>
		</el-drawer>
	</basic-container>
</template>

<script>
	import selFile from "@/components/file/selFile";
	import uploadPic from "@/components/file/uploadPic";
	import {
		bannerTitle
	} from '@/util/rej'
	import { testPirce} from '@/util/util';
	import {
		getList,
		remove,
		update,
		add,
		getPosList,
		getlistPoster,
		getDetail,
		getStoreDetail,
		getGoodsList,
		getActList,
		getMoneyDetail
	} from "@/api/base/store/seller/advert";
	import {
		mapGetters
	} from "vuex";
	var Dict = JSON.parse(localStorage.getItem("mall-dictionary")).content;

	export default {
		data() {
			return {
				apPriceFlag:true,//竞价判断
				moneyDetail: false,
				value: '',
				total: null, // 获取总数据量
				pageCount: null, // 获取总页数
				selectPage: 1, // 当前页数
				restoreTable: [], //当前页数数据
				selectQuery: "",
				firstEdit: false, //是否是第一次打开编辑框
				load: false,
				title: '新增广告',
				apPrice: '',
				tableData: [],
				innerVisible: false,
				isView: false,
				isApView: false,
				posData: [],
				typeData: [],
				editForm: [],
				activeName: 'A',
				addForm: {
					adTitle: "",
					adApId: "",
					mark: "",
					adType: "",
					adTypeName: '',
					adTypeValue: "",
					adBeginTime: "",
					adEndTime: "",
					adAccUrl: "",
				},
				idTitle: '',
				addrules: {
					adTitle: [{
						required: true,
						validator: bannerTitle,
						trigger: "blur"
					}],
					adBeginTime: [{
						required: true,
						message: "请选择开始时间",
						trigger: 'blur'
					}],
					adEndTime: [{
						required: true,
						message: "请选择结束时间",
						trigger: 'blur'
					}],
					adSlideSequence: [{
						required: true,
						message: "请输入图片序号",
						trigger: "blur"
					}],
					adStoreId: [{
						required: true,
						message: "请输入商品id",
						trigger: "blur"
					}],
					adAccUrl: [{
						required: true,
						message: "请选择广告图片",
						trigger: "blur"
					}],
					adPrice: [{
						required: true,
						message: "请输入竞价",
						trigger: "blur"
					},
						{
							validator: testPirce,
							trigger: 'blur'
						},
					]
				},
				editDialogVisible: false,
				dialogVisible: false,
				form: {},
				query: {},
				loading: true,
				rolesTree: [],
				rolesKeys: [],
				box: false,
				page: {
					pageSize: 10,
					currentPage: 1,
					total: 0
				},
				loadMing: true,
				formMoney: {},
				pageMoney: {
					pageSize: 10,
					currentPage: 1,
					total: 0
				},
				queryMoney: {},
				dataMoney: [],
				optionMoney: {
					size: "mini",
					excelBtn: false,
					addBtn: false,
					tip: false,
					editBtn: false,
					delBtn: false,
					border: true,
					index: false,
					selection: false,
					viewBtn: false,
					rowKey: "id",
					height: "auto",
					// calcHeight: 380,
					dialogType: "dialog",
					align: 'center',
					menuWidth: 150,
					menu: false,
					column: [{
							label: "创建时间",
							prop: "addTime",
							width:200,
							fixed: true,
						},
						// {
						// 	label: "用户id",
						// 	prop: "userId",
						// },
						{
							label: "用户IP",
							prop: "userIp",
						},/* {
							label: "点击入口",
							prop: "fromType",
							dicData: Dict.sTORE_REGISTER_TYPE,
						},*/ {
							label: "广告价格",
							prop: "adPrice",
						}, {
							label: "扣费状态",
							prop: "status",
							dicData: Dict.ADVERT_CLICKS_STATUS,
						},
					]
				},
				option: {
					size: "mini",
					excelBtn: false,
					addBtn: false,
					tip: false,
					editBtn: false,
					delBtn: false,
					border: true,
					index: false,
					selection: false,
					viewBtn: false,
					rowKey: "id",
					height: "auto",
					// calcHeight: 380,
					dialogType: "dialog",
					align: 'center',
					menuWidth: 200,
					searchMenuSpan:4,
					column: [{
							label: "广告名称",
							prop: "adTitle",
							search: true,
							fixed: true,
						},
						{
							label: "广告位名",
							prop: "apTitle",
							search: true,
							width:200,
							addDisplay: false,
							editDisplay: false,
						},
						{
							label: "广告位",
							prop: "adApId",
							hide: true,
							width:200,
							addDisplay: false,
							editDisplay: false,
						},
						{
							type: "select",
							label: "广告类型",
							prop: "adType",
							width:100,
							dicData: Dict.ADVERT_TYPE,
							rules: [{
								required: true,
								message: "请输入广告类型 1商品详情  2店铺  4促销活动 6秒杀活动 8拼团 7聚合页",
								trigger: "blur"
							}]
						},
						{
							type: "datetime",
							label: "开始时间",
							search: true,
							prop: "adBeginTime",
							format: "yyyy-MM-dd HH:mm:ss",
							valueFormat: "yyyy-MM-dd HH:mm:ss",
							width:150,
						},
						{
							type: "datetime",
							label: "结束时间",
							search: true,
							prop: "adEndTime",
							format: "yyyy-MM-dd HH:mm:ss",
							valueFormat: "yyyy-MM-dd HH:mm:ss",
							width:150,
						},
						{

							label: "广告状态",
							prop: "adStatus",
							type: 'switch',
							width:100,
							slot: true,
							cell: true,
						},
						{
							label: "广告上下架状态",
							prop: "deductionOfCharges",
							type: 'radio',
							cell: true,
							dicData: [{
								label: "正常状态",
								value: 0
							},
							{
								label: "广告币余额不足下架",
								value: 1
							},
							{
								label: "违规下架",
								value: 2
							}],
						},
						{
							label: "广告点击次数",
							prop: "adClickNum",
							addDisplay: false,
							editDisplay: false,
							hide: true,
							width:100,
						},
						{
							label: "竞价出价",
							prop: "adPrice",
							hide: true,
							width:100,
						},
						{
							label: "广告图片",
							hide: true,
							prop: "adAccUrl",
							width:150,
						},
						{
							label: "广告位id",
							prop: "adApId",
							hide: true,
						},

						{
							label: "广告类型对应的id值",
							prop: "adTypeValue",
							hide: true,
						},

						{
							type: "radio",
							label: "是否是系统广告",
							prop: "isSys",
							hide: true,
							dicData: [{
									label: "否",
									value: 0
								},
								{
									label: "是",
									value: 1
								}
							],
						}
					]
				},
				data: [],
				dicData: [],
				mark: ''
			};
		},
		watch: {
			dialogVisible(val) {
				if (!val) {
					this.$nextTick(() => {
						this.$refs['addForm'].resetFields()
					})
				}
			},
			'addForm.adType'() {
				if (!this.firstEdit) {
					//重置
					this.value = "";
					this.valueFlag = "";
					this.total = null; // 获取总数据量
					this.pageCount = null; // 获取总页数
					this.selectPage = 1; // 当前页数
					this.restoreTable = []; //当前页数数据
					this.selectQuery = "";
				}
				if (this.dialogVisible) {
					this.getSelectList();
				}

			}
		},
		created() {
			// 下拉广告位
			getPosList(1, 1, false).then(res => {
				const data = res.data;
				this.posData = data.data
			})
			this.dicData = JSON.parse(localStorage.getItem("mall-dictionary")).content;
			this.typeData = this.dicData.ADVERT_TYPE
		},
		components: {
			selFile,
			uploadPic
		},
		computed: {
			...mapGetters(["permission", 'userInfo', 'dictionariy']),
			permissionList() {
				return {

				};
			},
		},
		methods: {
			biddingDetail(id) {
				this.queryMoney.advertId = id
				this.onMoneyLoad(this.pageMoney);
				this.moneyDetail = true
			},

			getSelectList(query,pageFlag) {
				if(query == false && pageFlag != true){
					return;
				}
				if(query == true || query == false){
					this.valueFlag= "";
					this.query = "";
				}else{
					//商品选择框
					this.valueFlag= this.value;
					this.query = query;
				}
				//商品选择框
				//查询参数
				let param = {
					goodsName: this.query
				};
				if(this.addForm.adType == 1){
					if (this.firstEdit) {
						param = {
							id: this.valueFlag
						};
						this.firstEdit = false;
					}else{
						param={goodsName:this.query,goodsStatus:0};
					}
				}
				let getListMethod = getGoodsList;
				//1商品详情  2店铺  4促销活动 6秒杀活动 8拼团
				if (this.addForm.adType == 2) {
					getStoreDetail().then(res => {
						let store = res.data.data;
						let storeSelect = {
							storeName: store.storeName,
							id: store.id
						};
						this.restoreTable = [];
						this.restoreTable.push(storeSelect);
						if (this.firstEdit) {
							//编辑是回显问题
							this.firstEdit = false;
							this.total = 2;
							this.pageCount = 1;
						} else {
							this.total = res.data.count; // 数据总数量
							this.pageCount = Math.ceil(this.total / 10); // 因为我每次只请求20条， 所以算出总页数
						}
						this.value = this.restoreTable[0].storeName; //店铺只有一个，所以选取第一条数据;
					});
					return;
				} else if (this.addForm.adType == 4) {
					getListMethod = getActList;
					if (this.firstEdit) {
						param = {
							id: this.valueFlag
						};
						this.firstEdit = false;
					} else {
						param = {
							isPromotion: true,
						};
					}
				} else if (this.addForm.adType == 6) {
					getListMethod = getActList;
					if (this.firstEdit) {
						param = {
							id: this.valueFlag
						};
						this.firstEdit = false;
					} else {
						param = {
							acType: 3
						};
					}
				} else if (this.addForm.adType == 8) {
					getListMethod = getActList;
					if (this.firstEdit) {
						param = {
							id: this.valueFlag
						};
						this.firstEdit = false;
					} else {
						param = {
							acType: 2
						};
					}
				}
				getListMethod(this.selectPage, 10, param).then(res => {
					this.restoreTable = res.data.data;
					if (this.firstEdit) {
						//编辑时回显问题
						this.firstEdit = false;
						this.total = 2;
						this.pageCount = 1;
					} else {
						this.total = res.data.count; // 数据总数量
						this.pageCount = Math.ceil(this.total / 10); // 因为我每次只请求20条， 所以算出总页数
					}
				});
			},
			prevePage() {
				if (this.selectPage > 1) { // 判断点击的页数是否小于1
					--this.selectPage;
				};
				this.getSelectList(this.query,true);
			},
			nextPage() {
				if (this.selectPage < this.pageCount) { // 判断点击的页数是否小于总页数;
					++this.selectPage;
					this.getSelectList(this.query,true);
				}
			},
			changeAdPrice(val) {
				if (!this.apPrice) {
					this.$message({
						type: "error",
						message: "请选择广告位类型"
					});
				} else {
					if (this.apPrice > val) {
						this.$message({
							type: "error",
							message: "竞价不能低于选择的价格"
						})
						this.apPriceFlag=false
					}else{
						this.apPriceFlag=true
					}
				}
			},
			//点击竞价查询
			look() {
				this.innerVisible = true
				let orderBy = 0;
				let adApId = this.addForm.adApId
				getlistPoster(orderBy, adApId).then(res => {
					if (res.status == 200) {
						this.tableData = res.data.data.listMap
					}
				})
			},
			rowSwitchChange(row) {
				if (row.adStatus != 1) {
					update(row).then(res => {
						console.log(res)
						if (res.status == 200) {
							this.$message({
								type: "success",
								message: "关闭成功!"
							});
						}
					})
				} else {
					update(row).then(res => {
						console.log(res)
						if (res.status == 200) {
							this.$message({
								type: "success",
								message: "开启成功!"
							});
						}
					})
				}
			},
			//删除按钮
			delNew(row) {
				this.$confirm("确定将选择数据删除?", {
						confirmButtonText: "确定",
						cancelButtonText: "取消",
						type: "warning"
					})
					.then(() => {
						return remove(row.id)
					})
					.then(() => {
						this.onLoad(this.page);
						this.$message({
							type: "success",
							message: "操作成功!"
						});

					});
			},
			getAddTime() {
				if (this.addForm.adBeginTime > this.addForm.adEndTime) {
					this.$message({
						type: "error",
						message: "结束时间不能小于开始时间"
					});
					this.addForm.adEndTime = ''
				}
			},
			checkStartTime() {
				if (this.addForm.adEndTime != null && this.addForm.adEndTime != undefined && this.addForm.adEndTime != "") {
					if (this.addForm.adBeginTime > this.addForm.adEndTime) {
						this.$message({
							type: "error",
							message: "开始时间不能大于结束时间"
						});
						this.addForm.adBeginTime = '';
						return;
					}
				}
				if (this.addForm.adBeginTime < new Date().getTime()) {
					this.$message({
						type: "error",
						message: "开始时间不能小于当前时间"
					});
					this.addForm.adBeginTime = ''
				}
			},
			//选择广告类型
			getAdType(val) {
				for (let obj of this.typeData) {
					if (obj.value == val) {
						this.addForm.adTypeName = obj.label
						this.addForm.adType = obj.value
						if (obj.value == 1) {
							this.idTitle = '商品id'
						} else if (obj.value == 2) {
							this.idTitle = '店铺id'
						} else if (obj.value == 4) {
							this.idTitle = '促销活动id'
						} else if (obj.value == 6) {
							this.idTitle = '秒杀活动id'
						} else if (obj.value == 8) {
							this.idTitle = '拼团活动id'
						} else if (obj.value == 7) {
							this.idTitle = '聚合页id'
						}
					}
				}

			},
			// 选择图片
			selFileCallBack(obj) {
				this.addForm.adAccUrl = obj[0];
			},

			handleAdd() {
				this.title = "新增广告"
				this.isView = false
				this.isApView = false
				this.mark = ''
				this.addForm = {
					adTitle: "",
					adApId: "",
					mark: "",
					adType: "",
					adTypeName: '',
					adTypeValue: "",
					adBeginTime: "",
					adEndTime: "",
					adAccUrl: "",
				}
				this.dialogVisible = true;

			},
			closeDialog(addForm) {
				// this.apPriceFlag=true
				this.dialogVisible = false;
				this.firstEdit = true;
				this.onLoad(this.page, this.query)
				this.$nextTick(() => {
					this.$refs[addForm].resetFields();
				})
			},
			// 新增广告按钮
			submitAdvert(addForm) {
				console.log(this.apPriceFlag)
				if(this.apPriceFlag==true){
					console.log(11111)
					if(this.load==true){
						return;
					}
					this.load = true
					this.$refs[addForm].validate((valid) => {
						if (valid) {
							this.load = true
							if (this.activeName == 'A') {
									if (!this.addForm.adPrice) {
										this.$message({
											type: "error",
											message: "请输入竞价!"
										});
									} else {
										this.addForm.mark = this.mark;
										this.addForm.adTypeValue = this.value;
										add(this.addForm).then((res) => {
											if (res.status == 200) {
												this.$message({
													type: "success",
													message: "新增广告成功!"
												});
												this.onLoad(this.page, this.query)
												this.activeName = 'A'
												this.closeDialog(addForm)
											}
											//延迟三秒防重复提交
											setTimeout(()=>{
												this.load = false;
											},2000)
										})
									}

							} else if (this.activeName == 'B') {
									this.addForm.adTypeValue = this.value;
									update(this.addForm).then((res) => {
										if (res.status == 200) {
											this.$message({
												type: "success",
												message: "编辑广告成功!"
											});
											this.onLoad(this.page, this.query)
											this.dialogVisible = false;
											this.$refs[addForm].resetFields();
											this.activeName = 'A'
										}
										setTimeout(()=>{
											this.load = false;
										},2000)
									})

							}
						} else {
							this.load = false;
							this.$message({
								type: "error",
								message: "请正确填写广告信息!"
							});
							return false;
						}

					});
				}
			},
			getPosData(val) {
				//选择的竞价
				getDetail(val).then(res => {
					if (res.status == 200) {
						this.apPrice = res.data.data.apPrice
						if (res.data.data.mark == 1) {
							this.mark = '1'
						} else {
							this.mark = '2'
						}
					}
				})
			},

			// 点击编辑按钮展示数据详情
			editBtn(row) {
				this.value = row.adTypeValue;
				this.getSelectList();
				this.firstEdit = true;
				this.title = "编辑广告"
				this.activeName = 'B'
				this.addForm = JSON.parse(JSON.stringify(row));
				getDetail(row.adApId).then(res => {
					console.log(res.data.data);
					this.posData = [];
					let obj = {
						label:res.data.data.apTitle,
						value:res.data.data.id
					}
					this.posData.push(obj);
					console.log(this.posData)
				})
				this.getPosData(row.adApId)
				this.getAdType(row.adType)
				this.isView = false
				this.isApView = true
				this.dialogVisible = true
			},
			// 点击查看按钮展示数据详情
			detail(row) {
				this.value = row.adTypeValue;
				this.firstEdit = true;
				this.title = "查看广告"
				this.addForm = JSON.parse(JSON.stringify(row));
				this.getPosData(row.adApId)
				this.getAdType(row.adType)
				this.isView = true
				this.isApView = true
				this.dialogVisible = true
			},
			refreshMoneyChange() {
				this.onMoneyLoad(this.pageMoney);
			},
			currentMoneyChange(currentPage) {
				this.pageMoney.currentPage = currentPage;
			},
			sizeMoneyChange(pageSize) {
				this.pageMoney.pageSize = pageSize;
			},

			onMoneyLoad(page, params = {}) {
				this.loadMing = true;
				getMoneyDetail(
					page.currentPage,
					page.pageSize,
					Object.assign(params, this.queryMoney)
				).then(res => {
					this.loadMing = false;
					const data = res.data;
					this.pageMoney.total = data.count;
					this.dataMoney = data.data;
				});
			},
			searchReset() {
				this.query = {};
				this.onLoad(this.page);
			},
			searchChange(params,done) {
				console.log(params)
				this.page.currentPage=1
				this.query = params;
				this.onLoad(this.page, params,done);
			},
			currentChange(currentPage) {
				this.page.currentPage = currentPage;
			},
			sizeChange(pageSize) {
				this.page.pageSize = pageSize;
			},
			refreshChange() {
				this.onLoad(this.page);
			},
			onLoad(page, params = {},done) {
				this.loading = true;
				getList(
					page.currentPage,
					page.pageSize,
					Object.assign(params, this.query)
				).then(res => {
					if(done){
						done();
					}
					this.loading = false;
					const data = res.data;
					this.page.total = data.count;
					if (data.data.length > 0) {
						for (let item of data.data) {
							item.adBeginTime = item.adBeginTime.toString();
							item.adEndTime = item.adEndTime.toString();
							//转换数据类型
							item.adStatus = item.adStatus.toString()
						}
					}
					this.data = data.data;

				});
			}
		}
	};
</script>

<style scoped lang="scss">
	.image-slot {
		width: 40px;
		height: 40px;
		background: #f5f6f7;
		text-align: center;
	}

	.selectJob span {
		width: 120px;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.selectJob .text {
		padding-left: 10px;
		font-size: 14px;
		font-weight: bold;
		cursor: pointer;
		color: cornflowerblue;
	}
</style>
